<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.16"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>LibTools: H:/project/LibTools/src/thread/SpinLock.h 源文件</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">LibTools
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- 制作者 Doxygen 1.8.16 -->
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',false,false,'search.php','搜索');
});
/* @license-end */</script>
<div id="main-nav"></div>
<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li><li class="navelem"><a class="el" href="dir_bfedb72b9d87795234454f6223b9ab1e.html">thread</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">SpinLock.h</div>  </div>
</div><!--header-->
<div class="contents">
<a href="_spin_lock_8h.html">浏览该文件的文档.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="preprocessor">#ifndef  SPINLOCK_H</span></div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="preprocessor">#define  SPINLOCK_H</span></div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160; </div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="preprocessor">#include &quot;../tools/ShareApi.h&quot;</span></div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160; </div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<a class="code" href="tools_8h.html#a201ce692c9dca6599e5c12d00167419b">DEF_BEG_LIBTOOLS</a></div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160; </div>
<div class="line"><a name="l00011"></a><span class="lineno"><a class="line" href="class_spin_lock.html">   11</a></span>&#160;<span class="keyword">class </span><a class="code" href="class_spin_lock.html">SpinLock</a></div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;{</div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="keyword">private</span>:</div>
<div class="line"><a name="l00014"></a><span class="lineno"><a class="line" href="class_spin_lock.html#a560cab887a82a193a2892d6c47a19ace">   14</a></span>&#160;    <a class="code" href="tools_8h.html#a9154c0d0c21af4686624543215b4e5f2">LONG</a> <a class="code" href="class_spin_lock.html#a560cab887a82a193a2892d6c47a19ace">_bLock</a>;</div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;<span class="keyword">public</span>:</div>
<div class="line"><a name="l00016"></a><span class="lineno"><a class="line" href="class_spin_lock.html#a7dc17bb50466088acb8ea4a45d43b183">   16</a></span>&#160;    <a class="code" href="class_spin_lock.html#a7dc17bb50466088acb8ea4a45d43b183">SpinLock</a>(){</div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;        <a class="code" href="class_spin_lock.html#a560cab887a82a193a2892d6c47a19ace">_bLock</a> = 0;</div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;    }</div>
<div class="line"><a name="l00019"></a><span class="lineno"><a class="line" href="class_spin_lock.html#abb10f50b73ba8c3ef0390bc3f87dea4e">   19</a></span>&#160;    <span class="keywordtype">void</span> <a class="code" href="class_spin_lock.html#abb10f50b73ba8c3ef0390bc3f87dea4e">Lock</a>()</div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;    {</div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;        <span class="keywordflow">while</span>( <a class="code" href="namespace_share_api.html#aa020decf062bbd8dc399dd69c67a1d5b">ShareApi::InterlockedExchange</a>(&amp;<a class="code" href="class_spin_lock.html#a560cab887a82a193a2892d6c47a19ace">_bLock</a>,1) == 1 ) {<a class="code" href="namespace_share_api.html#a169d4ee242a5f842c91da9be8a179e18">Sleep</a>(1);} </div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;    }</div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;    </div>
<div class="line"><a name="l00024"></a><span class="lineno"><a class="line" href="class_spin_lock.html#a6186f76f703c9457877f9d12fab03f4f">   24</a></span>&#160;    <span class="keywordtype">void</span> <a class="code" href="class_spin_lock.html#a6186f76f703c9457877f9d12fab03f4f">UnLock</a>()</div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;    {</div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;        <a class="code" href="namespace_share_api.html#aa020decf062bbd8dc399dd69c67a1d5b">ShareApi::InterlockedExchange</a>(&amp;<a class="code" href="class_spin_lock.html#a560cab887a82a193a2892d6c47a19ace">_bLock</a>,0);</div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;    }</div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;};</div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160; </div>
<div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;<a class="code" href="tools_8h.html#ac909db71799bb22cb7d636a34cd785e4">DEF_END_LIBTOOLS</a></div>
<div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160; </div>
<div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;<span class="preprocessor">#endif</span></div>
</div><!-- fragment --></div><!-- contents -->
<div class="ttc" id="aclass_spin_lock_html_abb10f50b73ba8c3ef0390bc3f87dea4e"><div class="ttname"><a href="class_spin_lock.html#abb10f50b73ba8c3ef0390bc3f87dea4e">SpinLock::Lock</a></div><div class="ttdeci">void Lock()</div><div class="ttdef"><b>Definition:</b> <a href="_spin_lock_8h_source.html#l00019">SpinLock.h:19</a></div></div>
<div class="ttc" id="atools_8h_html_a201ce692c9dca6599e5c12d00167419b"><div class="ttname"><a href="tools_8h.html#a201ce692c9dca6599e5c12d00167419b">DEF_BEG_LIBTOOLS</a></div><div class="ttdeci">#define DEF_BEG_LIBTOOLS</div><div class="ttdef"><b>Definition:</b> <a href="tools_8h_source.html#l00036">tools.h:36</a></div></div>
<div class="ttc" id="atools_8h_html_ac909db71799bb22cb7d636a34cd785e4"><div class="ttname"><a href="tools_8h.html#ac909db71799bb22cb7d636a34cd785e4">DEF_END_LIBTOOLS</a></div><div class="ttdeci">#define DEF_END_LIBTOOLS</div><div class="ttdef"><b>Definition:</b> <a href="tools_8h_source.html#l00038">tools.h:38</a></div></div>
<div class="ttc" id="aclass_spin_lock_html_a560cab887a82a193a2892d6c47a19ace"><div class="ttname"><a href="class_spin_lock.html#a560cab887a82a193a2892d6c47a19ace">SpinLock::_bLock</a></div><div class="ttdeci">LONG _bLock</div><div class="ttdef"><b>Definition:</b> <a href="_spin_lock_8h_source.html#l00014">SpinLock.h:14</a></div></div>
<div class="ttc" id="aclass_spin_lock_html_a6186f76f703c9457877f9d12fab03f4f"><div class="ttname"><a href="class_spin_lock.html#a6186f76f703c9457877f9d12fab03f4f">SpinLock::UnLock</a></div><div class="ttdeci">void UnLock()</div><div class="ttdef"><b>Definition:</b> <a href="_spin_lock_8h_source.html#l00024">SpinLock.h:24</a></div></div>
<div class="ttc" id="aclass_spin_lock_html_a7dc17bb50466088acb8ea4a45d43b183"><div class="ttname"><a href="class_spin_lock.html#a7dc17bb50466088acb8ea4a45d43b183">SpinLock::SpinLock</a></div><div class="ttdeci">SpinLock()</div><div class="ttdef"><b>Definition:</b> <a href="_spin_lock_8h_source.html#l00016">SpinLock.h:16</a></div></div>
<div class="ttc" id="anamespace_share_api_html_aa020decf062bbd8dc399dd69c67a1d5b"><div class="ttname"><a href="namespace_share_api.html#aa020decf062bbd8dc399dd69c67a1d5b">ShareApi::InterlockedExchange</a></div><div class="ttdeci">LIBTOOLS long InterlockedExchange(long *Addend, long value)</div><div class="ttdef"><b>Definition:</b> <a href="_share_api_8cpp_source.html#l01754">ShareApi.cpp:1754</a></div></div>
<div class="ttc" id="anamespace_share_api_html_a169d4ee242a5f842c91da9be8a179e18"><div class="ttname"><a href="namespace_share_api.html#a169d4ee242a5f842c91da9be8a179e18">ShareApi::Sleep</a></div><div class="ttdeci">LIBTOOLS void Sleep(DWORD dwSleep)</div><div class="ttdoc">线程休眠函数,单位毫秒(ms)</div><div class="ttdef"><b>Definition:</b> <a href="_share_api_8cpp_source.html#l01817">ShareApi.cpp:1817</a></div></div>
<div class="ttc" id="atools_8h_html_a9154c0d0c21af4686624543215b4e5f2"><div class="ttname"><a href="tools_8h.html#a9154c0d0c21af4686624543215b4e5f2">LONG</a></div><div class="ttdeci">int LONG</div><div class="ttdef"><b>Definition:</b> <a href="tools_8h_source.html#l00128">tools.h:128</a></div></div>
<div class="ttc" id="aclass_spin_lock_html"><div class="ttname"><a href="class_spin_lock.html">SpinLock</a></div><div class="ttdoc">即将废弃的类</div><div class="ttdef"><b>Definition:</b> <a href="_spin_lock_8h_source.html#l00011">SpinLock.h:11</a></div></div>
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
制作者 &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.16
</small></address>
</body>
</html>
